N, V = map(int, input().split())

dp = [[0] * (V + 1) for i in range(N + 1)]

for i in range(1, N + 1):
    # 体积，价值，数量
    wi, vi, si = map(int, input().split())
    for j in range(0, V + 1):
        for k in range(0, min(si, j // wi) + 1):
            dp[i][j] = max(dp[i][j], dp[i - 1][j - k * wi] + k * wi)
print(dp[N][V])

N, V = map(int, input().split())
# N件物品，每件存在si件，拆成log件物品
w_v = []

for i in range(N):
    wi, vi, si = map(int, input().split())
    k = 1
    while si >= k:
        w_v.append((k * wi, k * vi))
        si -= k
        k *= 2
    if si != 0:
        w_v.append((si * wi, si * vi))
print(w_v)

dp = [0] * (V + 1)

for i, (w, v) in enumerate(w_v):
    for j in range(V, w - 1, -1):
        dp[j] = max(dp[j], dp[j - w] + v)

print(dp[V])
